package com.fsquare.api.endpoint.fulfillment;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.broadleafcommerce.core.order.domain.FulfillmentOption;
import org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption;
import org.broadleafcommerce.core.order.fulfillment.domain.FulfillmentPriceBand;
import org.broadleafcommerce.core.web.api.wrapper.FulfillmentGroupItemWrapper;
import org.broadleafcommerce.core.web.api.wrapper.FulfillmentGroupWrapper;
import org.broadleafcommerce.core.web.api.wrapper.FulfillmentOptionWrapper;
import org.broadleafcommerce.core.web.api.wrapper.OrderWrapper;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fsquare.shipping.api.wrapper.BandedPriceFulfillmentOptionWrapper;
import com.fsquare.shipping.api.wrapper.FulfillmentPriceBandWrapper;

@Component
@Scope("singleton")
@Path("/fulfillment/")
@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class FulfillmentWS extends com.fsquare.shipping.api.endpoint.FulfillmentWS {
	
	
	@Override
    @GET
    @Path("groups")
    public List<FulfillmentGroupWrapper> findFulfillmentGroupsForOrder(@Context HttpServletRequest request) {
        return super.findFulfillmentGroupsForOrder(request);
    }

    @Override
    @DELETE
    @Path("groups")
    public OrderWrapper removeAllFulfillmentGroupsFromOrder(@Context HttpServletRequest request,
            @QueryParam("priceOrder") @DefaultValue("true") boolean priceOrder) {
        return super.removeAllFulfillmentGroupsFromOrder(request, priceOrder);
    }

    @Override
    @POST
    @Path("group")
    public FulfillmentGroupWrapper addFulfillmentGroupToOrder(@Context HttpServletRequest request,
            FulfillmentGroupWrapper wrapper,
            @QueryParam("priceOrder") @DefaultValue("true") boolean priceOrder) {
        return super.addFulfillmentGroupToOrder(request, wrapper, priceOrder);
    }

    @Override
    @PUT
    @Path("group/{fulfillmentGroupId}")
    public FulfillmentGroupWrapper addItemToFulfillmentGroup(@Context HttpServletRequest request,
            @PathParam("fulfillmentGroupId") Long fulfillmentGroupId,
            FulfillmentGroupItemWrapper wrapper,
            @QueryParam("priceOrder") @DefaultValue("true") boolean priceOrder) {
        return super.addItemToFulfillmentGroup(request, fulfillmentGroupId, wrapper, priceOrder);
    }

	@Override
	@PUT
	@Path("group/{fulfillmentGroupId}/option/{fulfillmentOptionId}")
	public FulfillmentGroupWrapper addFulfillmentOptionToFulfillmentGroup(@Context HttpServletRequest request, @PathParam("fulfillmentGroupId") Long fulfillmentGroupId,
			@PathParam("fulfillmentOptionId") Long fulfillmentOptionId, @QueryParam("priceOrder") @DefaultValue("true") boolean priceOrder) {
		return super.addFulfillmentOptionToFulfillmentGroup(request, fulfillmentGroupId, fulfillmentOptionId, priceOrder);
	}

	@Override
	@GET
	@Path("options")
	public List<FulfillmentOptionWrapper> findFulfillmentOptions(@Context HttpServletRequest request, @QueryParam("type") String fulfillmentType) {
		return super.findFulfillmentOptions(request, fulfillmentType);
	}
	
	@Override
	@GET
	@Path("option")
	public FulfillmentOptionWrapper findFulfillmentOptionByid(@Context HttpServletRequest request, @QueryParam("id") Long fulfillmentOptionId) {
		return super.findFulfillmentOptionByid(request, fulfillmentOptionId);
	}
	
	@Override
	@GET
	@Path("option/priceBands")
	public List<FulfillmentPriceBandWrapper> readFulfillmentOptionPricebandsByFulfillmentOption(@Context HttpServletRequest request, @QueryParam("id") Long fulfillmentOptionId) {
		return super.readFulfillmentOptionPricebandsByFulfillmentOption(request, fulfillmentOptionId);
	}
	
	@Override
	@GET
	@Path("option/priceBand")
	public FulfillmentPriceBandWrapper readFulfillmentOptionPricebandsById(@Context HttpServletRequest request, @QueryParam("id") Long id) {
		return super.readFulfillmentOptionPricebandsById(request, id);
	}
	
	@Override
	@GET
	@Path("option/banded")
	public BandedPriceFulfillmentOptionWrapper readBandedPriceFulfillmentOptionWrapperById(@Context HttpServletRequest request, @QueryParam("id") Long id) {
		return super.readBandedPriceFulfillmentOptionWrapperById(request, id);
	}
	
	@Override
	@GET
	@Path("options/banded")
	public List<BandedPriceFulfillmentOptionWrapper> readAllBandedPriceFulfillmentOptionWrapper(@Context HttpServletRequest request) {
		return super.readAllBandedPriceFulfillmentOptionWrapper(request);
	}
	
	@Override
	@PUT
	@Path("option/banded")
	public BandedPriceFulfillmentOption addBandedPriceFulfillmentOption(@Context HttpServletRequest request, BandedPriceFulfillmentOptionWrapper wrapper) {
		return super.addBandedPriceFulfillmentOption(request, wrapper);
	}
	
	@Override
	@PUT
	@Path("option/band")
	public FulfillmentPriceBand addFulfillmentPriceBand(@Context HttpServletRequest request, FulfillmentPriceBandWrapper wrapper) {
		return super.addFulfillmentPriceBand(request, wrapper);
	}
	
	@Override
	@PUT
	@Path("option")
	public FulfillmentOption addFulfillmentOption(@Context HttpServletRequest request, FulfillmentOptionWrapper wrapper) {
		return super.addFulfillmentOption(request, wrapper);
	}
	
	@Override
	@DELETE
	@Path("option/banded")
	public void removeBandedPriceFulfillmentOption(@Context HttpServletRequest request, @QueryParam("id") Long id) {
		super.removeBandedPriceFulfillmentOption(request, id);
	}
	
	@Override
	@DELETE
	@Path("option/band")
	public void removeFulfillmentPriceBand(@Context HttpServletRequest request, @QueryParam("id") Long id) {
		super.removeFulfillmentPriceBand(request, id);
	}
	
	@Override
	@DELETE
	@Path("option")
	public void removeFulfillmentOption(@Context HttpServletRequest request, @QueryParam("id") Long id) {
		super.removeFulfillmentOption(request, id);
	}
}
